package com.power.service.impl;

import com.power.common.Contants;
import com.power.dao.NeedDealtDao;
import com.power.dao.impl.NeedDealtDaoImpl;
import com.power.ov.ResultData;
import com.power.service.NeedDealtService;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/10/05 10:30
 * Description:
 * Version: V1.0
 */
public class NeedDealtServiceImpl implements NeedDealtService {
    NeedDealtDao dealtDao=new NeedDealtDaoImpl();
    @Override
    public ResultData findNeedDealtById(String user_account, String role_id, String page, String limit) throws SQLException {
        int newPage=Integer.parseInt(page);
        int newLimit=Integer.parseInt(limit);
        ResultData resultData=new ResultData();
        List<Map<String,Object>> list=dealtDao.findNeedDealtById(user_account,role_id,newPage,newLimit);
        if (list.size()>0){
        for (Map map:list) {
            map.get("lssue_time");
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            map.put("lssue_time",simpleDateFormat.format(map.get("lssue_time")));
        }
        int count=dealtDao.NeedDeadltCount(user_account,role_id);
            resultData.setCode(Contants.TABLE_CODE);
            resultData.setCount(count);
            resultData.setMsg("查询成功");
            resultData.setData(list);
        }
        return resultData;
    }

    @Override
    public ResultData needDealtUpdate(String userAccount, String role_id, String task_id) throws SQLException {
        ResultData resultData=new ResultData();
        int res=dealtDao.needDealtUpdate(userAccount,role_id,task_id);
        if (res>0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("任务接收成功");
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("任务接收失败");
        }
        return resultData;
    }
}
